<template>
  <FormView
    title="请假申请"
    :toolbar-attrs="{
      buttons: [
        'back',
        {
          save: isDraft || flowContext.isStartNode,
          submit: hasBtn('submit'),
          withdraw: flowContext.canWithdraw,
          reject: flowContext.canReject,
          finish: hasBtn('finish')
        }
      ]
    }"
    :toolbar-listeners="{
      save: () => saveAndStart({ title: `${userName}的请假申请`, variables: { days: entity.days } }),
      submit: submitAudit,
      finish: () => submitAudit(),
      withdraw: () => withdrawAudit(),
      reject: () => reject()
    }">
    <FormHolder ref="form" :model="entity" :disabled="isDisabled" label-width="120px" label-position="right">
      <FormItemGroup block-title="基本信息">
        <FormRadioGroup
          v-model="entity.type"
          label="类型"
          required
          prop="type"
          classic
          radio-type="button"
          :options="[
            { label: '调体', value: '1' },
            { label: '事假', value: '2' },
            { label: '年假', value: '3' }
          ]" />
        <FormDatePicker v-model="entity.startTime" date-time label="开始时间" prop="startTime" />
        <FormDatePicker v-model="entity.endTime" date-time label="结束时间" prop="endTime" />
        <FormInputNumber v-model="entity.days" label="请假天数" prop="days" required />
        <FormTextarea v-model="entity.note" label="说明" prop="note" />
      </FormItemGroup>
    </FormHolder>
  </FormView>
</template>

<script>
  import { getObj, addObj, putObj } from '@/api/admin/leave'
  import flowForm from '@/vue/mixin/flow-form'

  export default {
    name: 'LeaveForm',
    docType: 'leave',
    relativeViewId: 'Tblhrleave',
    mixins: [flowForm],
    data() {
      return {
        entity: {
          id: null,
          applyerCode: '',
          title: '',
          type: '1',
          days: 1,
          startTime: null,
          endTime: null,
          companyId: '',
          companyName: '',
          deptId: '',
          deptName: '',
          note: '',
          createTime: '',
          creator: this.userId,
          updateTime: '',
          updator: '',
          status: 0
        }
      }
    },
    methods: {
      load: getObj,
      save: addObj,
      update: putObj
    }
  }
</script>
